package patten.xingwei.observer.demo1;

import patten.xingwei.observer.AbstractObserver;
import patten.xingwei.observer.ObserverSubject;

import java.util.ArrayList;
import java.util.List;

/**
 * Description：订单
 * Author：zwenzhi
 * Date：2023/11/17 10:02
 */
public class Order implements OrderSubject {
    private List<OrderObserver> observerList= new ArrayList<>();
    private String orderId;
    private String status;
    @Override
    public void addObserver(OrderObserver orderObserver) {
        this.observerList.add(orderObserver);
    }

    @Override
    public void removeObserver(OrderObserver orderObserver) {
        this.observerList.remove(orderObserver);
    }


    @Override
    public void notifyObserver() {
        for (OrderObserver orderObserver : this.observerList) {
            orderObserver.update(this);
        }
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
        notifyObserver();
    }
}
